/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.storage.api;

import com.jeesite.modules.storage.common.ServerResponse;
import com.jeesite.modules.sys.entity.Area;
import com.jeesite.modules.sys.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 区域Controller
 */
@RestController(value = "apiarea")
@RequestMapping(value = "/api/area")
class AreaController extends APIController {

    @Autowired
    private AreaService areaService;

    /**
     * 获取所有区域
     * @return 区域列表
     */
    @RequestMapping(method = RequestMethod.GET,value = "query")
    @ResponseBody
    public ServerResponse<List<Map>> query(){
        List<Area> areas = areaService.findList(new Area());
        List<Map> maps = new ArrayList<>();
        for (Area area : areas){
            Map map = new HashMap();
            map.put("level",area.getTreeLevel());
            map.put("code",area.getAreaCode());
            map.put("name",area.getAreaName());
            map.put("parentCode",area.getParentCode());
            maps.add(map);
        }
        return ServerResponse.createBySuccess(200,maps);
    }
}